package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.CategoryService;
import com.atguigu.spzx.model.entity.product.Category;
import com.atguigu.spzx.model.vo.common.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@Tag(name = "商品分类管理模块")
@RequestMapping("/admin/product/category")
public class CategoryController {
    @Resource
    CategoryService categoryService;
    /*
        导出时，只需要将 文件流写入到响应体中即可
     */
    @Operation(summary = "导出分类excel文件")
    @PostMapping("export")
    public void exportCates(HttpServletResponse response){
        categoryService.exportCates(response);
    }
    @Operation(summary = "导入分类excel数据")
    @PostMapping("import")
    public R importCates(MultipartFile file){
        categoryService.importCates(file);
        return R.ok();
    }

    @Operation(summary = "根据pid查询下一级商品分类集合")
    @GetMapping("listByPid/{pid}")
    public R listByPid(@PathVariable("pid")Long pid){
        List<Category> categoryList = categoryService.listByPid(pid);
        return R.ok("items" , categoryList);
    }

}
